#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include "operator.h"
#include "sort_algorithms.h"

using namespace std;

long long int compare_count, swap_count;

void getRandarr(vector<int> &, int);
void timing(void (*func)(vector<int>), vector<int>);
void compare(vector<int>);

int main(void)
{
	vector<int> array;
	vector<int>::iterator p_arr;
	int num_count = 30000;
	getRandarr(array, num_count);
	cout << "Random list" << endl;
	compare(array);
	cout << endl << "Sequence list" << endl;
	sort(array.begin(), array.end());
	compare(array);
	cout << endl << "Reverse list" << endl;
	sort(array.rbegin(), array.rend());
	compare(array);
	return 0;
}

void compare(vector<int> array)
{
	cout << "Direct insert sort" << endl;
	timing(insertSort, array);
	cout << "Binary insert sort" << endl;
	timing(binsertSort, array);
	cout << "Bubble sort" << endl;
	timing(bubbleSort, array);
	cout << "Quick sort" << endl;
	timing(quickSort, array);
	cout << "Select sort" << endl;
	timing(selectSort, array);
	cout << "Heap sort" << endl;
	timing(heapSort, array);
	cout << "Merge sort" << endl;
	timing(mergeSort, array);
}
 
void timing(void (*func)(vector<int>), vector<int> array)
{
	time_t begin, end;
	compare_count = swap_count = 0;
	begin = time(&begin);
	func(array);
	end = time(&end);
	cout << "Time used: " << difftime(end, begin) << endl;
	cout << "The number of comparisons: " << compare_count << endl;
	cout << "The number of exchange: " << swap_count << endl;
}

void getRandarr(vector<int> &array, int count)
{
	srand(time(0));
	int num;
	for(int i = 1; i <= count; i++)
	{
		num = rand();
		array.push_back(num);
	}
}
